<?php if (!defined('THINK_PATH')) exit(); /*a:3:{s:43:"D:\web\quan/app/index\view\index\index.html";i:1537432626;s:45:"D:\web\quan/app/index\view\member\bottom.html";i:1537432626;s:45:"D:\web\quan/app/index\view\public\footer.html";i:1537432627;}*/ ?>
<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>附近商家</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />

		<link rel="stylesheet" href="__PUBLIC__/static/wx/style/iconfont.css" />
		<link rel="stylesheet" href="__PUBLIC__/static/wx/style/style.css" />
		<link rel="stylesheet" href="__PUBLIC__/static/wx/style/new.css" />
		<script src="__PUBLIC__/static/js/jquery.min.js"></script>
	</head>

	<body style="background-color: #FFFFFF;">
		<div class="mui-content">
			<div class="fjsj_top">附近商家</div>
			<ul class="fjsj_list">

			</ul>
			<input type="hidden" id="page" value="1" />
		</div>
				<?php if($browder_type!=1): ?>
		<nav class="bottom">
			<div class="navbox">
				<a class=" <?php if($action=='index'&&$controller=='Index'): ?>mui-active<?php endif; ?>" href="<?php echo url('index/index'); ?>">
					<span class="iconfont icon-51"></span><br>
					<span class="mui-tab-label">附近商家</span>
				</a>
				<a class="right <?php if($action=='index'&&$controller=='Member'): ?>mui-active<?php endif; ?>" href="<?php echo url('member/index'); ?>">
					<span class="iconfont icon-gerenzhongxin"></span><br>
					<span class="mui-tab-label">个人中心</span>
				</a>
			</div>
		</nav>
<?php endif; ?>

	</body>

</html>
<script src="__PUBLIC__/static/js/jquery.min.js"></script>
<link rel="stylesheet" href="__PUBLIC__/static/layui/css/layui.css">
<script src="__PUBLIC__/static/layui/layui.all.js"></script>
<script>
var index = layer.load(1, {shade: false,time: 1.5 * 1000});
$(".layui-layer-loading").css("left", "50%");
</script>
<script src="__PUBLIC__/static/js/assist.js"></script>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.2&key=eef7f290ac06bdf05b246cebc8cb2fb6&callback=my_getAddress"></script>
<script src="__PUBLIC__/static/js/help.js "></script>
<script src="__PUBLIC__/static/js/assist.js "></script>
<script type="text/javascript" src="__INDEX__/js/menudown.js"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js "></script>
<script type="text/javascript">
	var gurl = "<?php echo $url; ?>";
	var news = {
		"title": "会员省钱啦",
		"desc": "吃喝玩乐购就去附近省钱啦合作商户,同城消费这里什么都有啦",
		"imgUrl": "https://"+document.domain+"__PUBLIC__/static/index/images/share.jpg",
		"link": gurl
	};
	share_set(news);
	//获取用户当前地址
	var map, geolocation;
	var btype = "<?php echo $btype; ?>";
	if(btype == 0) {
		get_data(0, 0);
	}
	var list=[];
	$("#page").val(1);
	function my_getAddress() {
		var longitude = getCookie('longitude');
		var latitude = getCookie('latitude');

		if(longitude && latitude) {
			get_data(longitude, latitude);
		} else {
			//加载地图，调用浏览器定位服务
			map = new AMap.Map('container', {
				resizeEnable: true
			});
			map.plugin('AMap.Geolocation', function() {
				geolocation = new AMap.Geolocation({
					enableHighAccuracy: true, //是否使用高精度定位，默认:true
					timeout: 10000, //超过10秒后停止定位，默认：无穷大
					buttonOffset: new AMap.Pixel(10, 20), //定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
					zoomToAccuracy: true, //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
					buttonPosition: 'RB'
				});
				map.addControl(geolocation);
				geolocation.getCurrentPosition();
				AMap.event.addListener(geolocation, 'complete', onComplete); //返回定位信息
				if(!getCookie('longitude') || getCookie('longitude') < 0) {
					//get_data(113.015137,113.015137);
				}

			});
			$('#container').hide();
		}

		//解析定位结果
		function onComplete(data) {
			setCookie('longitude', data.position.getLng());
			setCookie('latitude', data.position.getLat());
			get_data(data.position.getLng(), data.position.getLat());
		}
	}

	function get_data(lng, lat) {
		setCookie('longitude', lng);
		setCookie('latitude', lat);
		$.ajax({
			type: "post",
			data: {
				longitude: lng,
				latitude: lat,
				page: $("#page").val()
			},
			url: "<?php echo url('index/index/get_agents'); ?>",
			success: function(data) {
				var html = "";
				if(data.list) {
					list=list.concat(data.list);			
					for(var o in list) {
						var agent = list[o];
						var juli = agent.juli;
						var diz = agent.address;
						var begin_time = ''
						var end_time = '';
						var dk = 0;
						var unit = 'm';
						if(agent.is_score == 1) {
							dk = agent.ad_score;
						}
						var action = agent['action'];
						if(action == null) {
							action = "暂无";
						}
						if(juli > 1000) {
							juli = juli / 1000;
							unit = 'km';
						}
						if(diz && diz.length > 0) {
							diz = diz.replace('郴州市', '');
							diz = diz.replace('湖南省', '');
						} else {
							diz = '暂无';
						}
						if(agent.start_time && agent.start_time.length > 0) {
							begin_time = agent.start_time.substr(0, agent.start_time.length - 3);
						} else {
							begin_time = '00:00';
						}
						if(agent.end_time && agent.end_time.length > 0) {
							end_time = agent.end_time.substr(0, agent.end_time.length - 3);;
						} else {
							end_time = '00:00';
						}
						var logo = agent.logo;
						if(!logo) {
							logo = "__PUBLIC__/static/index/images/noimage.jpg";
						}

						var agent_name = agent.agent_name;
						var str = agent_name.length;
						if(str > 8) {
							agent_name = agent_name.substring(0, 8) + "...";
						}
						var url = "/index/index/map?lng=" + agent.longitude + "&lat=" + agent.latitude;
						html += "<li>" +
							"<a href='/index/index/shop_info?agent_id=" + agent.id + "'>" +
							"<div class='fjsj_img'><img src='" + logo + "'></div>" +
							"<div class='fjsj_infobox'>" +
							"<p class='dinw'>" + juli + unit + "</p>" +
							"<p class='nam'>" + agent_name + "</p>" +
							"<p class='weiz'><span class='iconfont icon-dingwei' data-ref='" + url + "'>" + diz + "" +
							"</span></p> " +
							"<p class='huod'>最新活动： " + action + "</p>" +
							"<p class='glj'>鼓励金最高可抵：<em>" + dk + "%</em></p>" +
							"</div>" +
							"</a>" +
							"</li>";
					}
					$('.fjsj_list').html(html);
					setevent();
				} else {
					$(".fjsj_list").html("<li>附近无商铺<li>");
				}
			}
		});
	}

	function setevent() {
		$(".icon-dingwei").click(function() {
			window.location.href = $(this).data("ref");
		})
	}

	$(window).scroll(function() {
		var longitude = getCookie("longitude");
		var latitude = getCookie("latitude");
		var scrollTop = $(window).scrollTop(); //滚动条高度
		var bodyheight = $(document).height(); //文档的高度
		var windowheight = window.innerHeight; //$(window).height();              //当前窗体的高度
		if((bodyheight - windowheight - scrollTop) == 0) {

			var index = layer.load(1, {
				shade: false,
				time: 1.5 * 1000
			});
			$.ajax({
				type: "post",
				data: {
					longitude: longitude, //113.015137,113.015137
					latitude: latitude,
					page: parseFloat($("#page").val()) + 1
				},
				url: "<?php echo url('index/index/get_agents'); ?>",
				success: function(data) {
					var html = "";
					if(data.list) {
						list=list.concat(data.list);	
						$("#page").val(parseFloat($("#page").val()) + 1);
						for(var o in list) {
							var agent = list[o];
							var juli = agent.juli;
							var diz = agent.address;
							var begin_time = ''
							var end_time = '';
							var dk = 0;
							var unit = 'm';
							if(agent.is_score == 1) {
								dk = agent.ad_score;
							}
							var action = agent['action'];
							if(action == null) {
								action = "暂无";
							}
							if(juli > 1000) {
								juli = juli / 1000;
								unit = 'km';
							}
							if(diz && diz.length > 0) {
								diz = diz.replace('郴州市', '');
								diz = diz.replace('湖南省', '');
							} else {
								diz = '暂无';
							}
							if(agent.start_time && agent.start_time.length > 0) {
								begin_time = agent.start_time.substr(0, agent.start_time.length - 3);
							} else {
								begin_time = '00:00';
							}
							if(agent.end_time && agent.end_time.length > 0) {
								end_time = agent.end_time.substr(0, agent.end_time.length - 3);;
							} else {
								end_time = '00:00';
							}
							var logo = agent.logo;
							if(!logo) {
								logo = "__PUBLIC__/static/index/images/noimage.jpg";
							}

							var agent_name = agent.agent_name;
							var str = agent_name.length;
							if(str > 8) {
								agent_name = agent_name.substring(0, 8) + "...";
							}
							var url = "/index/index/map?lng=" + agent.longitude + "&lat=" + agent.latitude;
							html += "<li>" +
								"<a href='/index/index/shop_info?agent_id=" + agent.id + "'>" +
								"<div class='fjsj_img'><img src='" + logo + "'></div>" +
								"<div class='fjsj_infobox'>" +
								"<p class='dinw'>" + juli + unit + "</p>" +
								"<p class='nam'>" + agent_name + "</p>" +
								"<p class='weiz'><span class='iconfont icon-dingwei' data-ref='" + url + "'>" + diz + "" +
								"</span></p> " +
								"<p class='huod'>最新活动： " + action + "</p>" +
								"<p class='glj'>鼓励金最高可抵：<em>" + dk + "%</em></p>" +
								"</div>" +
								"</a>" +
								"</li>";
						}
						$('.fjsj_list').html(html);
						setevent();
					} else {
						$(".fjsj_list").html("<li>附近无商铺<li>");
					}
				}
			});
		}
	})
</script>